package com.kerwin.utils;

import com.kerwin.sysmgt.entity.User;

public class UserThreadLocal {

    /*这里设置线程*/
    /*！！在多线程环境下，每个 user 都不一样，一定要考虑这个问题！！  这个是错的*/

    private static ThreadLocal<User> userThreadLocal = new ThreadLocal<User>();

    /*设置用户到线程里面*/
    public static void setUser(User user){
        userThreadLocal.set(user);
    }

    /*从线程里面拿用户*/
    public static User getUser(){
        User user = userThreadLocal.get();
        return user;
    }

    /*从线程获取用户名，用于日志*/
    public static String getUserName(){
        User user = userThreadLocal.get();
        String userName = user.getUserName();
        return userName;
    }


}
